using System.Collections.Generic;
using UnityEngine;

public class SelectableButtonController : MonoBehaviour
{
	public UIGrid grid;

	[HideInInspector]
	public SelectableButton selectedButton;

	public List<SelectableButton> allButtons = new List<SelectableButton>();

	public virtual bool SelectButton(SelectableButton buttonToSelect)
	{
		if (buttonToSelect != null && (buttonToSelect == selectedButton || !buttonToSelect.enabled))
		{
			return false;
		}
		if (selectedButton != null)
		{
			selectedButton.Select(false);
			selectedButton = null;
		}
		if (buttonToSelect == null)
		{
			return false;
		}
		buttonToSelect.Select(true);
		selectedButton = buttonToSelect;
		return true;
	}

	public virtual void DisableButton(SelectableButton buttonToDisable)
	{
		if (!(buttonToDisable == null))
		{
			buttonToDisable.Disable();
		}
	}

	public virtual void EnableButton(SelectableButton buttonToEnable)
	{
		if (!(buttonToEnable == null))
		{
			buttonToEnable.Enable();
		}
	}

	public virtual void ClearAllButtons()
	{
		for (int i = 0; i < allButtons.Count; i++)
		{
			Object.Destroy(allButtons[i].gameObject);
		}
		allButtons.Clear();
	}

	public virtual void AddNewButton(SelectableButton newButton)
	{
		allButtons.Add(newButton);
	}
}
